<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 礼品信息
 */
class Lpxx extends Common
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRiaght = '*';
    protected $lpxxModel = null;
    protected $lpxxCategoryModel = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->lpxxModel = new \app\admin\model\Lpxx();
        $this->lpxxCategoryModel =new \app\admin\model\LpxxCategory();
    }
    /**
     * 礼品信息分类列表
     *
     */
    public function getlpxxCategoryList()
    {
        $lpxxCategory = $this->lpxxCategoryModel
            ->where('show', 1)
            ->select();
        $this->outputData($lpxxCategory);
    }
    /**
     * 礼品信息列表
     */
    public function getlpxxList()
    {
        $page = $this->request->get('page') - 1;
        $page=$page>0?$page:0;
        $limit = $this->request->get('pageSize');
        $limit=$limit>0?$limit:5;
        $start = $page * $limit;
        $catid=$this->request->get('catid');
        //按分类
        if($catid){
            $where['catid']=$catid;
        }
        $lpxxList = $this->lpxxModel
            ->alias('f')
            ->join('LpxxCategory fc','f.catid=fc.id')
            ->limit($start,$limit)
            ->select();
        $this->outputData($lpxxList);
    }
    /**
     * 礼品信息
     */
    public function getlpxxDetail()
    {
        $id=$this->request->get('id');
        if(!is_numeric($id)){
            $this->outputError('参数错误');
        }
        $lpxxList = $this->lpxxModel
            ->alias('f')
            ->join('LpxxCategory fc','f.catid=fc.id')
            ->where('f.id',$id)
            ->find();
        $this->outputData($lpxxList);
    }
}